//
//  NSString+TGMDateTimeParser.m
//  TravelGuideMdd
//
//  Created by HanFeng on 1/2/15.
//  Copyright (c) 2015 mafengwo.com. All rights reserved.
//

#import "NSString+TGMDateTimeParser.h"

@implementation NSString (TGMDateTimeParser)

+ (NSDateFormatter *)__tgm_time_parser_formatter
{
    static NSDateFormatter *formatter = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
        formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:28800];
    });
    return formatter;
}

- (NSDate *)tgm_dateFromString
{
    return [[self.class __tgm_time_parser_formatter] dateFromString:self];
}

+ (NSString *)tgm_stringFromDate:(NSDate *)date
{
    return [[self __tgm_time_parser_formatter] stringFromDate:date];
}

@end
